package cn.wujiangbo.test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池创建方式对比
 */
public class ThreadTest_3 {

    public static void main(String[] args) {
        ExecutorService executorService1 = Executors.newCachedThreadPool();
        ExecutorService executorService2 = Executors.newFixedThreadPool(10);
        ExecutorService executorService3 = Executors.newSingleThreadExecutor();

        for(int i=1; i<=100; i++){
            executorService3.execute(new MyTask(i));
        }
    }
}

//任务类
class MyTask implements Runnable{

    int i;
    public MyTask(int i){
        this.i = i;
    }

    @Override
    public void run() {
        System.out.println("程序员：" + Thread.currentThread().getName() + "，正在做第" + i + "个任务");
        try {
            Thread.sleep(1000L);//模拟做任务花费的时间
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}